package com.hgb.mall.portal.controller;

import com.hgb.mall.common.api.CommonPage;
import com.hgb.mall.common.api.CommonResult;
import com.hgb.mall.mbg.entity.PmsComment;
import com.hgb.mall.portal.domain.CommentParam;
import com.hgb.mall.portal.services.CommentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
@RestController
@RequestMapping("/comment")
@Api(tags = "前台评论管理")
public class CommentController {
    @Autowired
    private CommentService commentService;
    @ApiOperation("获取商品评论")
    @RequestMapping(value = "/{productId}", method = RequestMethod.GET)
    public CommonResult<CommonPage<PmsComment>> detail(@PathVariable Long productId,
                                                       @RequestParam(required = false, defaultValue = "0") Integer pageNum,
                                                       @RequestParam(required = false, defaultValue = "5") Integer pageSize) {
        List<PmsComment> comments = commentService.list(productId,pageNum,pageSize);
        return CommonResult.success(CommonPage.restPage(comments));
    }

    @ApiOperation("添加商品评论")
    @RequestMapping(value = "/add", method = RequestMethod.POST)
    public CommonResult<Integer> addComment(@RequestBody CommentParam commentParam) {
        int count = commentService.add(commentParam);
        return CommonResult.success(count);
    }
}
